package intro;

import java.util.Map;
import java.util.TreeMap;

import org.newdawn.slick.Color;
import org.newdawn.slick.Font;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Music;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;

public class TextGameState extends BasicGameState {
	public int ID;

	private String[] lines;

	private Font font;

	private Color color;

	private Image background;

	private float x, y, rowInterval;

	private Map<Integer, Integer> button2GameStateID = new TreeMap<Integer, Integer>();

	private Music music;

	public Music getMusic() {
		return music;
	}

	public void setMusic(Music music) {
		this.music = music;
	}

	public TextGameState(int id) {
		super();
		ID = id;
	}

	public void addExitState(int keyCode, int gameStateID) {
		button2GameStateID.put(keyCode, gameStateID);
	}

	@Override
	public int getID() {
		return ID;
	}

	@Override
	public void enter(GameContainer container, StateBasedGame game)
			throws SlickException {
		super.enter(container, game);
		if (music != null)
			music.loop();
	}

	@Override
	public void leave(GameContainer container, StateBasedGame game)
			throws SlickException {
		super.leave(container, game);
		if (music != null)
			music.stop() ;
	}

	public void init(GameContainer container, StateBasedGame game)
			throws SlickException {
		System.out.println(getID());
	}

	public void render(GameContainer container, StateBasedGame game, Graphics g)
			throws SlickException {
		float rowY = y;
		g.drawImage(getBackground(), 0, 0);
		g.setFont(getFont());
		g.setColor(getColor());
		for (String line : lines)
			g.drawString(line, x, rowY += rowInterval);
	}

	public void update(GameContainer container, StateBasedGame game, int delta)
			throws SlickException {
		for (Integer key : button2GameStateID.keySet())
			if (container.getInput().isKeyPressed(key))
				game.enterState(button2GameStateID.get(key));
	}

	public Image getBackground() {
		return background;
	}

	public void setBackground(Image background) {
		this.background = background;
	}

	public Color getColor() {
		return color;
	}

	public void setColor(Color color) {
		this.color = color;
	}

	public Font getFont() {
		return font;
	}

	public void setFont(Font font) {
		this.font = font;
	}

	public String[] getLines() {
		return lines;
	}

	public void setLines(String[] lines) {
		this.lines = lines;
	}

	public float getRowInterval() {
		return rowInterval;
	}

	public void setRowInterval(float rowInterval) {
		this.rowInterval = rowInterval;
	}

	public float getX() {
		return x;
	}

	public void setX(float x) {
		this.x = x;
	}

	public float getY() {
		return y;
	}

	public void setY(float y) {
		this.y = y;
	}

}
